package com.wpw.dream.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorDemo {

	public static void main(String[] args) {
//		ThreadPoolExecutor
//		new ThreadPoolEx
		Executors.newCachedThreadPool();
		Executors.newFixedThreadPool(3);
		//newFixedThreadPool的一种极端情况
		Executors.newSingleThreadExecutor();
		
		new PriorityBlockingQueue<>();
		
		//无界队列drainTo

	    /*new ArrayBlockingQueue(1).drainTo(c); 
	    new LinkedBlockingQueue().drainTo(c); 
	    new PriorityBlockingQueue().drainTo(c);
	    new DelayQueue().drainTo(c);
	    new SynchronousQueue().drainTo(c);
	    new LinkedTransferQueue().drainTo(c);
	    new LinkedBlockingDeque().drainTo(c);*/
		
		/*ArrayBlockingQueue //bounded
		LinkedBlockingQueue //optionally-bounded
		PriorityBlockingQueue //unbounded
		DelayQueue //unbounded
		SynchronousQueue //each insert operation must wait for a corresponding remove operation by another thread, and vice versa.
		LinkedTransferQueue //unbounded
		LinkedBlockingDeque //optionally-bounded
*/
		
		/*ConcurrentLinkedDeque<String> list = new ConcurrentLinkedDeque<>();
		list.add("a");
		System.out.println(list.pollLast());
		System.out.println(list.getLast());
		System.out.println(list.pollLast());*/
		ArrayBlockingQueue<String> aq = new ArrayBlockingQueue<String>(1);
		aq.add("a");
//		aq.add("b");

		/*try {
			boolean offer = aq.offer("b", 2, TimeUnit.SECONDS);
			
			String a = aq.poll();
			System.out.println(a);
			String b = aq.poll(5, TimeUnit.SECONDS);
			System.out.println(b);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}*/
		LinkedBlockingDeque	list=new LinkedBlockingDeque(2);
		try {
			list.add("a");
			list.put("B");
			list.add("C");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
